<?php
    /**
     * xDataBase
     *
     * The xDataBase class provides connection and using data base
     *
     * @copyright Copyright (c) 2011, xEngine Progect
     */
     
    /**
     * xDataBase
     *
     * The xDataBase class provides connection and using data base
     *
     * @copyright Copyridfdfd, xEngine Progect
     */
    class ServerRegistrationManager {
        private $tockens;
        /**
         *
         * This function is Block construct
         *
         * @access public
         */
         
        public function __construct() {
          //TODO constructor
          //TODO add top up controll
        }
        
        public function registerGameServer($serverData) {
          $iJUser  = iJFactory::singleton('iJUser');
          spr($serverData);
          /*Data validation*/
          if (!iJValidation::Unex_symb($serverData['name']) || !isset($serverData['name'])){
            // iJMessages::display('fail', 'fail', 'incorrect_template_name');
             return 'fail';
          }       
          
          if (!iJValidation::name($serverData['login']) || !isset($serverData['login'])){
            // iJMessages::display('fail', 'fail', 'incorrect_template_name');
             return 'fail';
          }     
          
          if (!iJValidation::name($serverData['pass']) || !isset($serverData['pass'])){
            // iJMessages::display('fail', 'fail', 'incorrect_template_name');
             return 'fail';
          }    
          
          if (!iJValidation::validString($serverData['childs']) || !isset($serverData['childs'])){
            // iJMessages::display('fail', 'fail', 'incorrect_template_name');
             return 'fail';
          }    
          
           if (!iJValidation::URL($serverData['url']) || !isset($serverData['url'])){
            // iJMessages::display('fail', 'fail', 'incorrect_template_name');
             return 'fail';
          }    
          $serverData['file'] = ltrim($serverData['url'], 'http://');
          $serverData['file'] = ltrim($serverData['url'], 'https://');
          
          $stop = strpos($serverData['file'], '.');
          if($stop === false) {
            return;
          }
          $serverData['file'] = substr($serverData['file'], 0, $stop);
          spr($serverData['file']);
        
          $serverData['ip'] = $iJUser->getIP();
          /**
           * $ServerRegistrationManager  =  iJFactory::singleton('ServerRegistrationManager'); 
   $info['name']  = 'xxxx';
   $info['login'] = 'xxxx';
   $info['pass'] = 'xxxx';
   $info['childs'] = 'xx,xx';
   $info['url'] = 'http://googledocs.blogspot.co';
   spr($ServerRegistrationManager->registerGameServer($info));
   die();
           */
          return 'register';
        }
        
 
    }
?>